/**
 * SmartKiwi namespace.
 */
if ("undefined" == typeof(SmartKiwi)) {
  var SmartKiwi = {};
};

/**
 * Controls the browser overlay for the Hello World extension.
 */
SmartKiwi = {
  /**
   * Says 'Hello' to the user.
   */
	catchSelection : function(aEvent) { 
		prefs = Components.classes["@mozilla.org/preferences-service;1"]
				.getService(Components.interfaces.nsIPrefService)
				.getBranch("smartkiwi.");
		prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);

		var numport = (prefs.getCharPref("numport")) ? prefs.getCharPref("numport") : "8080";
		alert(numport);
		var ws = new WebSocket("ws://127.0.0.1:"+numport);
		alert("connected");
		ws.onopen = function(e) {
		};
		alert("OPENNED");
		ws.send("SENDTEXT \""+content.document.getSelection()+"\"");
		alert("SENT");
		ws.close();
	}
};
